/**
 * 
 */
package com.seeyon.ctp.common.usermessage;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 
 * @author <a href="mailto:tanmf@seeyon.com">Tanmf</a>
 * @version 1.0 2007-3-8
 */
public class MessageContent implements java.io.Serializable {

	private static final long serialVersionUID = -7616248769132825770L;

	/**
	 * 国际化资源的key，统一定义在<code>com.seeyon.ctp.common.usermessage.resources.i18n.UserMessageResources</code>中<br>
	 * 
	 * 支持多个key，显示的时候将这些key串起来<br>
	 * 
	 * 
	 * Object[] - 第一列是key, 第二列是params
	 * @see com.seeyon.ctp.common.usermessage.resources.i18n.UserMessageResources
	 */
	private List<Object[]> keys = new ArrayList<Object[]>(); 

	/**
	 * 如果你的国际化资源文件是独立的，请制定resource名称
	 */
	private String resource;
	
	/**
	 * 正文内容，用于转发邮件
	 */
	private String bodyContent;
	private String bodyType;
	private Date bodyCreateDate;
	
	/**
	 * 1普通，2重要， 3非常重要
	 */
	private int importantLevel = 1;
	/**
	 * 是否模板类消息
	 */
	private boolean fromTemplate = false;
	/**
	 * 模板id
	 */
	private Long templateId = null;
	//kk:客开追加消息关联 MESSAGE_RULE 规则 start
	private Long messageRuleId;

	private String stateName;

	public String getStateName() {
		return stateName;
	}

	public void setStateName(String stateName) {
		this.stateName = stateName;
	}

	public Long getMessageRuleId() {
		return messageRuleId;
	}

	public void setMessageRuleId(Long messageRuleId) {
		this.messageRuleId = messageRuleId;
	}
	//kk:客开追加消息关联 MESSAGE_RULE 规则 end
	
	/**
	 * 强制发消息的通道
	 */
	private List<String> pipelines = null;

	public MessageContent() {
	}

	public MessageContent(String key, Object... params) {
		keys.add(new Object[]{key, params});
	}

	/**
	 * 构造一个MessageContent对象
	 * 
	 * @param key
	 * @param params
	 * @return
	 */
	public static MessageContent get(String key, Object... params) {
		return new MessageContent(key, params);
	}

	public String getResource() {
		return resource;
	}
	
	/**
	 * 往一个消息内容中添加多个key，解析是时候，会将这些key对应的文本依次串接起来
	 * 
	 * @param key
	 * @param params
	 * @return
	 */
	public MessageContent add(String key, Object... params){
		keys.add(new Object[]{key, params});
		return this;
	}
	
	/**
	 * 正文内容，用于转发邮件
	 * 
	 * @param bodyContent
	 * @param bodyType
	 * @return
	 */
	public MessageContent setBody(String bodyContent, String bodyType, Date bodyCreateDate){
		this.bodyContent = bodyContent;
		this.bodyType = bodyType;
		this.bodyCreateDate = bodyCreateDate;
		
		return this;
	}
	
	public List<Object[]> getKeys(){
		return this.keys;
	}

	/**
	 * 指定resource，不从系统默认的resource读取
	 * 
	 * @param resource
	 */
	public MessageContent setResource(String resource) {
		this.resource = resource;
		
		return this;
	}

	public String getBodyContent() {
		return bodyContent;
	}

	public Date getBodyCreateDate() {
		return bodyCreateDate;
	}

	public String getBodyType() {
		return bodyType;
	}

	public int getImportantLevel() {
		return importantLevel;
	}
	
	public boolean isFromTemplate(){
		return !(templateId == null);
	}
	public Long getTemplateId() {
		return templateId;
	}

	public void setTemplateId(Long templateId) {
		this.templateId = templateId;
	}

	/**
	 * 设置主题的重要的程度
	 * @param importantLevel  1普通， 2重要， 3非常重要
	 * @return
	 */
	public MessageContent setImportantLevel(Integer importantLevel) {
		if(importantLevel != null){
			this.importantLevel = importantLevel;
		}
		
		return this;
	}

    public List<String> getPipelines() {
        return pipelines;
    }

    public void setPipelines(List<String> pipelines) {
        this.pipelines = pipelines;
    }
	
	/**
	 * 得到正文
	 * 
	 * @return
	 */
//	public String getBodyContent() {
//		if(Strings.isBlank(bodyType) || Strings.isBlank(bodyContent) || bodyCreateDate == null){
//			return "";
//		}
//		
//		if(Constants.EDITOR_TYPE_HTML.equals(bodyType)){
//			return bodyContent;
//		}
//		else{
//			try {
//				return StrExtractor.getText(bodyType, bodyContent, bodyCreateDate);
//			}
//			catch (Exception e) {
//			}
//			
//			return "";
//		}
//	}
	
	
	
}
